package com.haredot.controller;

import com.haredot.entity.User;
import com.haredot.result.R;
import com.haredot.service.UserService;
import com.haredot.validation.Insert;
import com.haredot.validation.Update;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {

    @Resource
    private UserService userService ;


    @PostMapping("/register")
    public  R<?>  register(@RequestBody @Validated(Insert.class) User user) {
        return userService.saveUsr(user);
    }

    @PostMapping("/api/token")
    public R<?> login(@Validated(Update.class) User user) {
        // 接收参数、并查询数据库
        return userService.loginSys(user);
    }


    @PutMapping("/api/token")
    public R<?> login(@RequestParam("refresh") String refresh) {
        // 接收参数、并查询数据库
        return userService.refreshToken(refresh);
    }

}
